﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Ext ThemeR</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <style>
body { BACKGROUND: #FFF; COLOR: #D4D4D4; FONT-FAMILY: arial, helvetica, san-serif; FONT-SIZE: 12px; MARGIN: 0; PADDING: 0; TEXT-ALIGN: center; }
select,input { FONT-SIZE: 12px; }img { BORDER: 0; } a { COLOR: #999; }a:hover { COLOR: #e04f92; }
#everything { WIDTH: 770px; MARGIN: 0 auto; TEXT-ALIGN: left; PADDING-BOTTOM: 25px; }
#colorspy { border: 2px solid #EEEEEE; padding: 7px 0 20px 20px; margin: 0 0 7px 0; font-size: 16px; text-align: left; COLOR: #555; background: #fbfbfb; }
#colorspy a { COLOR: #e04f92; }
#colorspy legend { font-size: 17px; color: #bbb; padding: 0; }
.botLine { BORDER-TOP: 1px solid #EEE; WIDTH: 370px; MARGIN-TOP: 9px; PADDING-TOP: 9px; COLOR: #999; }
.botLine a { COLOR: #e04f92; }
.botLine a:hover { COLOR: #F360BB; }
#plugin { BACKGROUND: #0d0d0d; COLOR: #AAA; CURSOR: move; DISPLAY: block; FONT-FAMILY: arial; FONT-SIZE: 11px; PADDING: 7px 10px 11px 10px; _PADDING-RIGHT: 0; Z-INDEX: 1; POSITION: absolute; WIDTH: 199px; _width: 210px; _padding-right: 0px; }
#plugin br { CLEAR: both; MARGIN: 0; PADDING: 0;  }
#plugin select { BORDER: 1px solid #333; BACKGROUND: #FFF; POSITION: relative; TOP: 4px; }
#plugHEX { FLOAT: left; position: relative; top: -1px; }
#plugCLOSE { FLOAT: right; cursor: pointer; MARGIN: 0 8px 3px; _MARGIN-RIGHT: 10px; COLOR: #FFF; -moz-user-select: none; -khtml-user-select: none; user-select: none; }
#plugHEX:hover,#plugCLOSE:hover { COLOR: #FFD000;  }
#plugCUR { float: left; width: 10px; height: 10px; font-size: 1px; background: #FFF; margin-right: 3px; }
#SV { background: #FF0000 url('media/SatVal.png'); _BACKGROUND: #FF0000; POSITION: relative; CURSOR: crosshair; FLOAT: left; HEIGHT: 166px; WIDTH: 167px; _WIDTH: 166px; MARGIN-RIGHT: 10px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='media/SatVal.png', sizingMethod='scale'); -moz-user-select: none; -khtml-user-select: none; user-select: none; }
#SVslide { BACKGROUND: url('media/slide.gif'); HEIGHT: 9px; WIDTH: 9px; POSITION: absolute; _font-size: 1px; line-height: 1px; }
#H { BORDER: 1px solid #000; CURSOR: crosshair; FLOAT: left; HEIGHT: 154px; POSITION: relative; WIDTH: 19px; PADDING: 0; TOP: 4px; -moz-user-select: none; -khtml-user-select: none; user-select: none; }
#Hslide { BACKGROUND: url('media/slideHue.gif'); HEIGHT: 5px; WIDTH: 33px; POSITION: absolute; _font-size: 1px; line-height: 1px; }
#Hmodel { POSITION: relative; TOP: -5px; }
#Hmodel div { HEIGHT: 1px; WIDTH: 19px; font-size: 1px; line-height: 1px; MARGIN: 0; PADDING: 0; }

 </style>
</head>
<body>

<div id="everything">

   <div id="plugin"  style="TOP: 58px; Z-INDEX: 20;">
	<div id="plugCUR"></div><div id="plugHEX" onmousedown="stop=0; setTimeout('stop=1',100);">FFFFFF</div>
	<div id="SV" onmousedown="HSVslide('SVslide','plugin',event)" title="Saturation + Value">
	 <div id="SVslide" style="TOP: -4px; LEFT: -4px;"><br /></div>
	</div>
	<form id="H" onmousedown="HSVslide('Hslide','plugin',event)" title="Hue">
	 <div id="Hslide" style="TOP: -7px; LEFT: -8px;"><br /></div>
	 <div id="Hmodel"></div>
	</form>
   </div>
   
<input type="button" value="Generate Theme" onclick="genTheme()">
<label for="themeName">Theme&nbsp;Name:</label>
<input type="text" id="themeName" name="themeName" value="new">
<iframe id="TDLTHM" style="display:none"></iframe>
 </div>
</div>

<script type="text/javascript">
var curTh;
var curFth;
var thn = "new";
function setThm(){
thn = $("themeName").value
}
function genTheme(){
setThm()
var c = curTh;
$("TDLTHM").src="thememaker.php?r="+c[0]+"&g="+c[1]+"&b="+c[2]+"&tname="+thn
}
/* DHTML Color Picker v1.0.3, Programming by Ulyses, ColorJack.com */
/* Updated August 24th, 2007 */

function $(v) { return(document.getElementById(v)); }
function $S(v) { return(document.getElementById(v).style); }
function absPos(o) { var r={x:o.offsetLeft,y:o.offsetTop}; if(o.offsetParent) { var v=absPos(o.offsetParent); r.x+=v.x; r.y+=v.y; } return(r); }  
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function toggle(v) { $S(v).display=($S(v).display=='none'?'block':'none'); }
function within(v,a,z) { return((v>=a && v<=z)?true:false); }
function XY(e,v) { var z=agent('msie')?[event.clientX+document.body.scrollLeft,event.clientY+document.body.scrollTop]:[e.pageX,e.pageY]; return(z[zero(v)]); }
function XYwin(v) { var z=agent('msie')?[document.body.clientHeight,document.body.clientWidth]:[window.innerHeight,window.innerWidth]; return(!isNaN(v)?z[v]:z); }
function zero(v) { v=parseInt(v); return(!isNaN(v)?v:0); }

/* PLUGIN */

var maxValue={'h':360,'s':100,'v':100}, HSV={0:360,1:100,2:100};
var hSV=165, wSV=162, hH=163, slideHSV={0:360,1:100,2:100}, zINDEX=15, stop=1;

function HSVslide(d,o,e) {

	function tXY(e) { tY=XY(e,1)-ab.y; tX=XY(e)-ab.x; }
	function mkHSV(a,b,c) { return(Math.min(a,Math.max(0,Math.ceil((parseInt(c)/b)*a)))); }
	function ckHSV(a,b) { if(within(a,0,b)) return(a); else if(a>b) return(b); else if(a<0) return('-'+oo); }
	function drag(e) { if(!stop) { if(d!='drag') tXY(e);
	
		if(d=='SVslide') { ds.left=ckHSV(tX-oo,wSV)+'px'; ds.top=ckHSV(tY-oo,wSV)+'px';
		
			slideHSV[1]=mkHSV(100,wSV,ds.left); slideHSV[2]=100-mkHSV(100,wSV,ds.top); HSVupdate();

		}
		else if(d=='Hslide') { var ck=ckHSV(tY-oo,hH), j, r='hsv', z={};
		
			ds.top=(ck-5)+'px'; slideHSV[0]=mkHSV(360,hH,ck);
 
			for(var i=0; i<=r.length-1; i++) { j=r.substr(i,1); z[i]=(j=='h')?maxValue[j]-mkHSV(maxValue[j],hH,ck):HSV[i]; }

			HSVupdate(z); $S('SV').backgroundColor='#'+hsv2hex([HSV[0],100,100]);

		}
		else if(d=='drag') { ds.left=XY(e)+oX-eX+'px'; ds.top=XY(e,1)+oY-eY+'px'; }

	}}

	if(stop) { stop=''; var ds=$S(d!='drag'?d:o);

		if(d=='drag') { var oX=parseInt(ds.left), oY=parseInt(ds.top), eX=XY(e), eY=XY(e,1); $S(o).zIndex=zINDEX++; }
		else { var ab=absPos($(o)), tX, tY, oo=(d=='Hslide')?2:4; ab.x+=10; ab.y+=22; if(d=='SVslide') slideHSV[0]=HSV[0]; }

		document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; }; drag(e);

	}
}

function HSVupdate(v) { 

var ha = hsv2rgb(HSV=v?v:slideHSV)
var unit = ha[0]
var gv = ha[1]/unit 
var bv = ha[2]/unit
var tot = [1,gv,bv]
var curFth = tot;
//console.log(tot)
function rd(num){
var ack = 10000
var pnum = num * ack
var pnuma = Math.floor(pnum)
return pnuma/ack
}
v=hsv2hex(HSV=v?v:slideHSV);

//$('plugID').innerHTML = rd(tot[0])+","+rd(tot[1])+","+rd(tot[2])

curTh = [rd(tot[0]),rd(tot[1]),rd(tot[2])]

	$('plugHEX').innerHTML=curTh.join();
	$S('plugCUR').background='#'+v;
	//$S('plugID').background='#'+v;
	
	return(v);

}

function loadSV() { var z='';

	for(var i=hSV; i>=0; i--) z+="<div style=\"BACKGROUND: #"+hsv2hex([Math.round((360/hSV)*i),100,100])+";\"><br /><\/div>";
	
	$('Hmodel').innerHTML=z;
	
}

/* CONVERSIONS */

function toHex(v) { v=Math.round(Math.min(Math.max(0,v),255)); return("0123456789ABCDEF".charAt((v-v%16)/16)+"0123456789ABCDEF".charAt(v%16)); }
function rgb2hex(r) { return(toHex(r[0])+toHex(r[1])+toHex(r[2])); }
function hsv2hex(h) { return(rgb2hex(hsv2rgb(h))); }	

function hsv2rgb(r) { // easyrgb.com/math.php?MATH=M21#text21

    var R,B,G,S=r[1]/100,V=r[2]/100,H=r[0]/360;

    if(S>0) { if(H>=1) H=0;

        H=6*H; F=H-Math.floor(H);
        A=Math.round(255*V*(1.0-S));
        B=Math.round(255*V*(1.0-(S*F)));
        C=Math.round(255*V*(1.0-(S*(1.0-F))));
        V=Math.round(255*V); 

        switch(Math.floor(H)) {

            case 0: R=V; G=C; B=A; break;
            case 1: R=B; G=V; B=A; break;
            case 2: R=A; G=V; B=C; break;
            case 3: R=A; G=B; B=V; break;
            case 4: R=C; G=A; B=V; break;
            case 5: R=V; G=A; B=B; break;

        }

        return([R?R:0,G?G:0,B?B:0]);

    }
    else return([(V=Math.round(V*255)),V,V]);

}

/* LOAD */

loadSV();

$S('plugin').display='block';
$S('SVslide').top=(80/100*170-7)+'px';
HSVupdate([0,0,20]);

</script>
</body>
</html>